/**
 * Created by yyj on 2015/10/28.
 */
$(function(obj){

    //点击关闭按钮
    $('.press_btn2.Close').click(function(){
    	var index = parent.layer.getFrameIndex(window.name);
    	parent.$('.checkAll').removeAttr('checked');
        parent.layer.close(index);
    })
    
    //点击查看按钮
    $('.press_btn3.Look').click(function(){
    	var roleId=$("#roleId").val();
    	parent.$('.checkAll').removeAttr('checked');
     	window.location.href="initLookSysRolePrivilege.do?roleId="+roleId;
    
    });
    
    //点击添加按钮
     $('.press_btn1.Keep').click(function(){
     	var index = parent.layer.getFrameIndex(window.name);
     	var checkedNodes = new Array();
        var treeObj = $.fn.zTree.getZTreeObj("treeWay");
			var nodes = treeObj.getCheckedNodes(true);
			if (nodes.length > 0) {
				for(var i=0;i<nodes.length;i++){
						var tId = nodes[i].id;
						checkedNodes. push(tId);
				}
			}
		var roleId = $("#roleId").val();
		checkedNodes = checkedNodes.join(",");
        	$.ajax({
            url:"addPrivilegeRole.do",
            type:"post",
            dataType: 'json',
            data:{
        		"roleId":roleId,
        		"checkedNodes":checkedNodes
            },
            success:function(result){
                if(result.data){
                   	parent.paging(1);
                   	parent.$('.checkAll').removeAttr('checked');
                    parent.layer.msg('修改成功', {time:1300});
       			 	parent.layer.close(index);
                }else{
                    parent.layer.msg('修改失败！', {time:1000});
                }
            }
        });
    })
    
    
    
    
var setting = {
    check: {
        enable: true,
        chkboxType: { "Y": "ps", "N": "s" }
    },
    data: {
        key: {
            url:"u"
        },
        simpleData: {
            enable: true
        }
    },
    callback: {
        onClick:onClick
    }
};

	var roleId=$("#roleId").val();
	


	$.ajax({
		type: 'POST',
		dataType : "json",
		data:{
        		"roleId":roleId
            },
		url: "initPrivilege.do",//请求的action路径
		error: function () {//请求失败处理函数
			layer.msg('请求失败！！',{time:2000});
		},
		success:function(result){ //请求成功后处理函数。  
			var treeNodes = eval("("+result.lstTree+")");
			//var treeNodes = result.lstTree;   //把后台封装好的简单Json格式赋给treeNodes
			//console.log(treeNodes);
			$.fn.zTree.init($("#treeWay"), setting, treeNodes); 
			
		}
	});
	
	
    
});

function onClick(event, treeId, treeNode, clickFlag) {
  
    
}



